package app.beit.finportal.service;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;

import app.beit.finportal.bean.NewsBean;
import app.beit.finportal.dao.NewsDao;
import app.beit.finportal.entity.News;
import app.beit.finportal.service.convert.NewsConvert;

public class NewsService {

	@Autowired
	private NewsDao newsDao;
	
	public List<NewsBean> getAllBackdoor() throws Exception{
		final List<News> entities = this.newsDao.getAllBackdoor();
		if(entities != null && entities.size() > 0){
			return NewsConvert.entityToBean(entities);
		}
		
		return null;
	}
	
	public List<NewsBean> getAll() throws Exception{
		final List<News> entities = this.newsDao.getAll();
		if(entities != null && entities.size() > 0){
			return NewsConvert.entityToBean(entities);
		}
		
		return null;
	}
	
	public List<NewsBean> getAllLastedDate() throws Exception{
		final List<News> entities = this.newsDao.getAllLastestDate();
		if(entities != null && entities.size() > 0){
			return NewsConvert.entityToBean(entities);
		}
		
		return null;
	}
	
	public NewsBean getById(final String id) throws Exception{
		final News entities = this.newsDao.getById(id);
		if(entities != null){
			return NewsConvert.entityToBean(entities);
		}
		
		return null;
	}
	
	public void add(final NewsBean bean) throws Exception{
		this.newsDao.add(NewsConvert.beanToEntity(bean));
	}
	
	public void update(final NewsBean bean) throws Exception{
		this.newsDao.update(NewsConvert.beanToEntity(bean));
	}
	
	public void delete(final NewsBean bean) throws Exception{
		this.newsDao.delete(NewsConvert.beanToEntity(bean));
	}
}
